#!usr/bin/env python  
# -*- coding:utf-8 -*-
""" 
@author:robot
@file: solution.py 
@version:
@time: 2024/01/22 
"""
from collections import Counter


def solve_method(numbers1, numbers2):
    count1 = Counter(numbers1)
    count2 = Counter(numbers2)

    same_number_map = {}
    is_flagged = True

    for number, count in count1.items():
        if number in count2:
            is_flagged = False
            same_number_count = min(count, count2[number])
            same_number_map.setdefault(same_number_count, []).append(number)

    if is_flagged:
        return "NULL"

    result = sorted(same_number_map.keys())
    output = []
    for count in result:
        same_number_map[count].sort()
        nums = ",".join(map(str, same_number_map[count]))
        output.append(f"{count}:{nums}")

    return output


# numbers1 = [1, 2, 2, 3, 4, 5]
# numbers2 = [2, 2, 3, 4, 4, 5, 5]
numbers1 = list(map(int, input().split(",")))
numbers2 = list(map(int, input().split(",")))
# 调用 solve_method 函数
result = solve_method(numbers1, numbers2)

# 打印结果
for line in result:
    print(line)
